package com.learn.shop.service.impl;

import com.learn.shop.pojo.entriy.SNovelSort;
import com.learn.shop.mapper.SNovelSortMapper;
import com.learn.shop.service.SNovelSortService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import org.springframework.beans.factory.annotation.Autowired;

/**
 * 小说分类表(SNovelSort)表服务实现类
 *
 * @author zhengdechang
 * @since 2021-12-20 16:30:06
 */
@Service
public class SNovelSortServiceImpl implements SNovelSortService {
    @Autowired
    private SNovelSortMapper sNovelSortMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public SNovelSort queryById(Integer id) {
        return this.sNovelSortMapper.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param sNovelSort  筛选条件
     * @param pageRequest 分页对象
     * @return 查询结果
     */
    @Override
    public Page<SNovelSort> queryByPage(SNovelSort sNovelSort, PageRequest pageRequest) {
        long total = this.sNovelSortMapper.count(sNovelSort);
        return new PageImpl<>(this.sNovelSortMapper.queryAllByLimit(sNovelSort, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param sNovelSort 实例对象
     * @return 实例对象
     */
    @Override
    public SNovelSort insert(SNovelSort sNovelSort) {
        this.sNovelSortMapper.insert(sNovelSort);
        return sNovelSort;
    }

    /**
     * 修改数据
     *
     * @param sNovelSort 实例对象
     * @return 实例对象
     */
    @Override
    public SNovelSort update(SNovelSort sNovelSort) {
        this.sNovelSortMapper.update(sNovelSort);
        return this.queryById(sNovelSort.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.sNovelSortMapper.deleteById(id) > 0;
    }
}
